dispatcher = require '../../../util/dispatcher'

module.exports = (app)->
	new Handler app

class Handler
	constructor: (app)->
		@app = app


	queryEntry:(msg, session, next)->
		uid = msg.uid
		if(!uid)
			next null, {code: 500}
			return
		connectors = @app.getServersByType 'connector'
	
		if !connectors || connectors.length == 0 
			next null, {code: 500}
			return

		res = dispatcher.dispatch uid, connectors
		next null, {
			code: 200,
			host: res.host,
			port: res.clientPort
		}

